#include "abstractemotionmanager.h"
#include "abstractemotion.h"


namespace Emotion {

AbstractEmotionManager::AbstractEmotionManager(QObject *parent) :
    QObject(parent)
{
}


AbstractEmotionManager::~AbstractEmotionManager()
{

}


void AbstractEmotionManager::loadEmotion()
{
    for (int index = 1; index <= count(); index++) {
        append(createEmotion(index));
    }
}


void AbstractEmotionManager::append(AbstractEmotion *emotion)
{
    if (emotion == NULL)
        return;

    m_codeToEmotionMap.insert(emotion->code(), emotion);
    m_nameToEmotionMap.insert(emotion->name(), emotion);
    m_fullPathToEmotionMap.insert(emotion->fullPath(), emotion);

    m_nameToCodeMap.insert(emotion->name(), emotion->code());
    m_codeToNameMap.insert(emotion->code(), emotion->name());

    m_emotionList.append(emotion);
}


int AbstractEmotionManager::size() const
{
    return m_emotionList.size();
}


AbstractEmotion *AbstractEmotionManager::findByCode(const QString &code) const
{
    return m_codeToEmotionMap.value(code);
}


AbstractEmotion *AbstractEmotionManager::findByName(const QString &name) const
{
    return m_nameToEmotionMap.value(name);
}


AbstractEmotion *AbstractEmotionManager::findByFullPath(const QString &fullPath) const
{
    return m_fullPathToEmotionMap.value(fullPath);
}


QString AbstractEmotionManager::getNameByCode(const QString &code) const
{
    return m_codeToNameMap.value(code);
}


QString AbstractEmotionManager::getCodeByName(const QString &name) const
{
    return m_nameToCodeMap.value(name);
}

} // namespace Emotion
